package flexo.examples;

import flexo.math.*;

public class Test_Graphic_Text extends Test_Graphic_Base
{
	flexo.scene.Node root;
	flexo.scene.Node textNode;
	flexo.scene.Node gridNode;
	Quaternion rotation;
	
	public static void main(String[] args)
	{
		run("flexo.examples.Test_Graphic_Text");
	}
	
	public void init()
	{
		super.init();
		rotation = Quaternion.createRotationY(0.1f);
		
		root = mainScene.addChild("root");
		root.setPosition(new Vector(0,0,0));
		
		textNode = root.addChild("text");
		gridNode = root.addChild("grid");
		
		flexo.graphic.Material mat = graphic.addMaterial("gridMat", "textureRepeat");
		flexo.graphic.ShaderParam param = mat.getShaderParam("tex");
		param.setValue("textures/grid.png");
		param = mat.getShaderParam("repeatU");
		param.setValue(50.0f);
		param = mat.getShaderParam("repeatV");
		param.setValue(50.0f);
		
		flexo.graphic.entity.Entity grid = graphic.addQuad(50, 50);
		grid.setMaterial("gridMat");
		grid.attachTo(gridNode);
		gridNode.setRotation(new flexo.math.Quaternion(new flexo.math.Vector(1,0,0),-90.0f));
		gridNode.setPosition(new flexo.math.Vector(0,-3,0));
		
		flexo.graphic.entity.Text text = graphic.addText("fonts/Impact.xml",13);
		flexo.graphic.Material fontMat = graphic.addMaterial("fonts/Impact", "default");
		fontMat.setFaceCulling(false);
		fontMat.getShaderParam("tex").setValue("fonts/Impact.png");
		text.setMaterial("fonts/Impact");
		fontMat.setBlending(flexo.graphic.Material.Blending.TRANSPARENT_MASK);
		
		text.setText("Hello world");		
		text.attachTo(textNode);
	}

	public void cleanUp()
	{
	}	

	public void update()
	{
		rotation.fromAxis(new flexo.math.Vector(0,1,0),getElapsedTime() * 20);
		textNode.rotate(rotation);
	}	
}
